using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Managers.ResourceManagerV2.Runtime;

namespace WorldMapBase.Tile.Pool
{
    public class RtsEffectPool : ObjectPool<GameObject>
    {
        private HashSet<GameObject> _usingList;
        
        private int _initCount;
        private GameObject _originObject;
        private Transform _parent;

        public string Name = "";
        
        public RtsEffectPool(int capacity,
            int initCount,
            GameObject originObject,
            Transform parent) : base(capacity,true,2,5,5)
        {
#if UNITY_EDITOR
            _name = "RtsEffectPool：" + originObject.name;
#endif
            Name = "Effect: " + originObject.name;
            
            _usingList = new HashSet<GameObject>();
            _initCount = initCount;
            _originObject = originObject;
            _parent = parent;
            
            OnInit(_initCount);
        }

        protected override GameObject ConstructItem()
        {
            var go = GameObject.Instantiate(_originObject, _parent, true);
            go.SetActive(false);
            return go;
        }

        protected override void OnGetObject(GameObject obj)
        {
            _usingList.Add(obj);
            obj.SetActive(true);
        }

        protected override void BeforeRecover(GameObject obj)
        {
            _usingList.Remove(obj);
            obj.SetActive(false);
        }
    }
}
